﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import Classes.util.*;
    import com.adobe.crypto.*;

    public class SecureRand {

        protected static const HARD_CODED_SECRET:String = "YOUR_LIKE_AN_8";
        protected static const DEBUG_BUFFER_MAXLEN:int = 7;

        protected static var m_secretHandhsake:String = "";
        protected static var debugBuffer:Array = [];

        public static function getAndClearDebugBuffer():String{
            var _local1:Array = SecureRand.debugBuffer;
            SecureRand.debugBuffer = [];
            return (_local1.join(" "));
        }
        protected static function getSecretHandshake():String{
            return (m_secretHandhsake);
        }
        protected static function setSecretHandshake(_arg1:String):void{
            m_secretHandhsake = _arg1;
        }
        public static function rand(_arg1:int, _arg2:int, _arg3:String):int{
            Global.player.rollCounter = (Global.player.rollCounter + 1);
            var _local4:Number = Global.player.rollCounter;
            PerformanceTracker.rollCount = Global.player.rollCounter;
            var _local5:String = Global.player.uid;
            var _local6:String = ((((((HARD_CODED_SECRET + "::") + getSecretHandshake()) + "::") + _local5) + "::") + _local4);
            var _local7:int = ((_arg2 - _arg1) + 1);
            var _local8:String = ("0x" + MD5.hash(_local6).substring(0, 8));
            var _local9:Number = Number(_local8);
            var _local10:int = (_local9 % _local7);
            var _local11:int = (_local10 + _arg1);
            GlobalEngine.log("Secure Rand", ((((((("Calling rand(" + _arg1) + ", ") + _arg2) + ", ") + Global.player.rollCounter) + ") => ") + _local11));
            SecureRand.debugBuffer.push(((((_arg3 + ":") + Global.player.rollCounter) + "=>") + _local11));
            if (debugBuffer.length > DEBUG_BUFFER_MAXLEN){
                debugBuffer.splice(0, (debugBuffer.length - DEBUG_BUFFER_MAXLEN));
            };
            return (_local11);
        }
        public static function randPerFeature(_arg1:int, _arg2:int, _arg3:String, _arg4:String=""):int{
            if (Global.player.rollCounterMap[_arg3] == null){
                Global.player.rollCounterMap[_arg3] = 0;
            };
            Global.player.rollCounterMap[_arg3] = (Global.player.rollCounterMap[_arg3] + 1);
            var _local5:Number = Global.player.rollCounterMap[_arg3];
            var _local6:String = Global.player.uid;
            var _local7:String = ((((((((HARD_CODED_SECRET + "::") + getSecretHandshake()) + "::") + _local6) + "::") + _arg3) + "::") + _local5);
            var _local8:int = ((_arg2 - _arg1) + 1);
            var _local9:String = ("0x" + MD5.hash(_local7).substring(0, 8));
            var _local10:Number = Number(_local9);
            var _local11:int = (_local10 % _local8);
            var _local12:int = (_local11 + _arg1);
            GlobalEngine.log("Secure Rand", ((((((((("Calling rand(" + _arg3) + ", ") + _arg1) + ", ") + _arg2) + ", ") + _local5) + ") => ") + _local12));
            SecureRand.debugBuffer.push(((((((_arg3 + ":") + _arg4) + ":") + _local5) + "=>") + _local12));
            if (debugBuffer.length > DEBUG_BUFFER_MAXLEN){
                debugBuffer.splice(0, (debugBuffer.length - DEBUG_BUFFER_MAXLEN));
            };
            return (_local12);
        }

    }
}//package Classes 
